﻿using System;
using System.Collections.Generic;

namespace TextCompare
{
    class CompareControl
    {
        public CompareControl()
        {
            Controllers = new Dictionary<CompareOption, ICompareControl>
            {
                {CompareOption.String, new CompareStringControl()},
                {CompareOption.Char,new CompareCharControl()}
            };
        }

        public CompareResult Compare(string source, string target, CompareOption compareOption)
        {
            return new CompareResult(Controllers[compareOption].GenerateComparedText(source, target), Controllers[compareOption].CorrectPercent, compareOption);
        }

        public ITextMatcher TextMatcher(string source, string target, CompareOption compareOption)
        {
            return Controllers[compareOption].TextMatcher(source, target);
        }

        private IDictionary<CompareOption, ICompareControl> Controllers { get; set; }
    }

    [Serializable]
    class CompareResult
    {
        public CompareResult(IEnumerable<MatchPoint> matchPoints, double correctPercent, CompareOption compareOption)
        {
            this.matchPoints = matchPoints;
            this.correctPercent = correctPercent;
            this.compareOption = compareOption;
        }

        public CompareResult()
        {
        }

        public IEnumerable<MatchPoint> MatchPoints { get { return matchPoints; } }
        public double CorrectPercent { get { return correctPercent; } }
        public CompareOption CompareOption { get { return compareOption; } }

        private IEnumerable<MatchPoint> matchPoints;
        private double correctPercent;
        private CompareOption compareOption;
    }
}
